﻿#include "MovieTrans.h"
#include <QFileInfo>
#include <QDir>

MovieTrans::MovieTrans(TransferProxy *proxy)
    :FileTransfer(proxy) {

}

void MovieTrans::send(const QVariant &var, const QVariant &extra) {
    QString path = var.toString();
    path = path.remove("file:///");
    sendFile(path);
    //"<a href=\"file:///D:/BaiduNetdiskDownload/QT/XM/build-TopCom2-Desktop_Qt_5_14_2_MSVC2017_64bit-Release/Server/24-总结0.avi\">喜洋洋与灰太狼.mp4<br></a>"
    QString fileName = QFileInfo(path).fileName();
    QString movieLink= QString("<a href=\"file:///%1\">%2\n</a>").arg(path).arg(fileName);
    qDebug() << "send movieLink = " << movieLink;
    mTransproxy->updataComInfo(true, movieLink);
}

QString MovieTrans::transferPrefix() {
    return prefix();
}

QString MovieTrans::prefix() {
    return "Movie";
}

void MovieTrans::saveOverFunc() {
    QString path = getSaveDir() + mSaveFileName;
    QString movieLink= QString("<a href=\"file:///%1\">%2\n</a>").arg(path).arg(mSaveFileName);
    qDebug() << "receive movieLink = " << movieLink;
    mTransproxy->updataComInfo(true, movieLink);
}

QString MovieTrans::getSaveDir() {
    QString saveDir = QDir::currentPath() + "/Temp/Movie/";
    //路径不存在就创建
    CheckPathIsExist(saveDir);
    return saveDir;
}
